﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace RiskMan.DataClass.Models.RM
{
    /// <summary>
    /// Модель данных для строки Risk Manager
    /// </summary>
    [Serializable]
    public class RmItem : INotifyPropertyChanged, ISerializable
    {
        public bool IsShowMessage = false;

        #region private

        private bool _considerVmnd;
        private double _comisBlock;
        private bool _runComicBlock;
        private bool _checked = false;
        private bool _isRun = false;
        private String _account;
        private List<String> _accountList;
        private String _clientCode;
        private List<String> _clientCodeList;
        private bool _isBlock = false;
        private int _kGo;
        private String _variable;
        //private int _Stage;
        //private int _Unblock;
        private double _drowDown;
        private String _typeCalcutation;

        private double _profitBlock;
        //private double _reductionGO;
        //private double _reductionGOEvening;
        //private double _TimeStrartreductionGOEvening;

        private String _typeEnterLimite;
 
        private string _status;
        private int _id;

        private AccountLimiteItem _accountLimeteItem;
        private bool _useDefensePofit;
        private double _planProfit;
        private bool _activeDefensePofit;
        private double _decreaseProfit;
        #endregion

        #region public

        
        /// <summary>
        /// 
        /// </summary>
        public string Status
        {
            get { return _status; }
            set
            {
                if (_status != value)
                {
                    _status = value;
                    RaisePropertyChanged("Status");
                }
            }
        }
           
        /// <summary>
        /// минимальное значение по прибыли, до которого может опуститься счет
        /// </summary>
        public double DecreaseProfit
        {
            get { return _decreaseProfit; }
            set
            {
                if (_decreaseProfit != value)
                {
                    _decreaseProfit = value;
                    RaisePropertyChanged("DecreaseProfit");
                }
            }
        }

        /// <summary>
        /// внутрення переменная для активации защиты прибыли
        /// </summary>
        public bool ActiveDefensePofit
        {
            get { return _activeDefensePofit; }
            set
            {
                if (_activeDefensePofit != value)
                {
                    _activeDefensePofit = value;
                    RaisePropertyChanged("ActiveDefensePofit");
                }
            }
        }

        /// <summary>
        /// Планируемая прибыль для активации защиты прибыли
        /// </summary>
        public double PlanProfit
        {
            get { return _planProfit; }
            set
            {
                if (_planProfit != value)
                {
                    _planProfit = value;
                    RaisePropertyChanged("PlanProfit");
                }
            }
        }

        /// <summary>
        /// включение защиты прибыли
        /// </summary>
        public bool UseDefensePofit
        {
            get { return _useDefensePofit; }
            set
            {
                if (_useDefensePofit != value)
                {
                    _useDefensePofit = value;
                    RaisePropertyChanged("UseDefensePofit");
                }
            }
        }

        /// <summary>
        /// Временны расчеты по ВМ и НД
        /// </summary>
        public AccountLimiteItem AccountLimeteItem
        {
            get { return _accountLimeteItem; }
            set
            {
                if (_accountLimeteItem != value)
                {
                    _accountLimeteItem = value;
                    RaisePropertyChanged("AccountLimeteItem");
                }
            }
        }

        public bool ConsiderVMND
        {
            get { return _considerVmnd; }
            set { _considerVmnd = value; }
        }
        public double ComisBlock
        {
            get { return _comisBlock; }
            set { _comisBlock = value; }
        }
        public bool RunComicBlock
        {
            get { return _runComicBlock; }
            set { _runComicBlock = value; }
        }
        /// <summary>
        /// Нужна ли ручная блокировка
        /// </summary>
        public bool Check
        {
            get { return _checked; }
            set
            {
                if (_checked != value)
                {
                    _checked = value;
                    RaisePropertyChanged("Check");
                }
            }
        }
        /// <summary>
        /// Запущен или нет робот
        /// </summary>
        public bool isRun
        {
            get { return _isRun; }
            set
            {
                if ( _isRun != value )
                {
                    _isRun = value;
                    RaisePropertyChanged( "isRun" );
                }
            }
        }

        /// <summary>
        /// ручная блокировка по счету
        /// </summary>
        public bool IsBlock
        {
            get { return _isBlock; }
            set
            {
                if ( _isBlock != value )
                {
                    _isBlock = value;
                    RaisePropertyChanged( "IsBlock" );
                }
            }
        }

        /// <summary>
        /// счет фортс
        /// </summary>
        public String Account
        {
            get { return _account; }
            set
            {
                if ( _account != value )
                {
                    _account = value;
                    RaisePropertyChanged( "Account" );
                }
            }
        }
        /// <summary>
        /// Прибыль по достижению которой начинается происходить блокировка счета
        /// </summary>
        public double ProfitBlock
        {
            get { return _profitBlock; }
            set
            {
                if (_profitBlock != value)
                {
                    _profitBlock = value;
                    RaisePropertyChanged("ProfitBlock");
                }
            }
        }
        public List<String> AccountList
        {
            get { return _accountList; }
            set
            {
                if ( _accountList != value )
                {
                    _accountList = value;
                    RaisePropertyChanged( "AccountList" );
                }
            }
        }
        public String ClientCode
        {
            get { return _clientCode; }
            set
            {
                if ( _clientCode != value )
                {
                    _clientCode = value;
                    RaisePropertyChanged( "ClientCode" );
                }
            }
        }
        public List<String> ClientCodeList
        {
            get { return _clientCodeList; }
            set
            {
                if ( _clientCodeList != value )
                {
                    _clientCodeList = value;
                    RaisePropertyChanged( "ClientCodeList" );
                }
            }
        }

        public String Variable
        {
            get { return _variable; }
            set
            {
                if ( _variable != value )
                {
                    _variable = value;
                    RaisePropertyChanged( "Variable" );
                }
            }
        }
        //public List<String> VariableList
        //{
        //    get { return _VariableList; }
        //    set
        //    {
        //        if ( _VariableList != value )
        //        {
        //            _VariableList = value;
        //            RaisePropertyChanged( "VariableList" );
        //        }
        //    }
        //}
        //public int Stage
        //{
        //    get { return _Stage; }
        //    set
        //    {
        //        if ( _Stage != value )
        //        {
        //            _Stage = value;
        //            RaisePropertyChanged( "Stage" );
        //        }
        //    }
        //}
        //public int Unblock
        //{
        //    get { return _Unblock; }
        //    set
        //    {
        //        if ( _Unblock != value )
        //        {
        //            _Unblock = value;
        //            RaisePropertyChanged( "Unblock" );
        //        }
        //    }
        //}
        public double DrowDown
        {
            get { return _drowDown; }
            set
            {
                if ( _drowDown != value )
                {
                    _drowDown = value;
                    RaisePropertyChanged( "DrowDown" );
                }
            }
        }

        ///// <summary>
        ///// Пониженное ГО, указывается в процентах от базавого не дневную сессию
        ///// </summary>
        //public double ReductionGO
        //{
        //    get { return _reductionGO; }
        //    set
        //    {
        //        if (_reductionGO != value)
        //        {
        //            _reductionGO = value;
        //            RaisePropertyChanged("ReductionGO");
        //        }
        //    }
        //}

        ///// <summary>
        ///// Пониженное ГО, указывается в процентах от базавого на вечернюю сессию
        ///// </summary>
        //public double ReductionGOEvening
        //{
        //    get { return _reductionGOEvening; }
        //    set
        //    {
        //        if (_reductionGOEvening != value)
        //        {
        //            _reductionGOEvening = value;
        //            RaisePropertyChanged("ReductionGOEvening");
        //        }
        //    }
        //}

        ///// <summary>
        ///// Время когда начинает действовать пониженное ГО для вечерней сессии.
        ///// </summary>
        //public double TimeStrartreductionGOEvening
        //{
        //    get { return _TimeStrartreductionGOEvening; }
        //    set
        //    {
        //        if (_TimeStrartreductionGOEvening != value)
        //        {
        //            _TimeStrartreductionGOEvening = value;
        //            RaisePropertyChanged("TimeStrartreductionGOEvening");
        //        }
        //    }
        //}

        public string TypeCalcutation
        {
            get { return _typeCalcutation; }
            set
            {
                if ( _typeCalcutation != value )
                {
                    _typeCalcutation = value;
                    RaisePropertyChanged("TypeCalcutation");
                }
            }
        }
        //public List<string> TypeRaschList
        //{
        //    get { return _TypeRaschList; }
        //    set
        //    {
        //        if ( _TypeRaschList != value )
        //        {
        //            _TypeRaschList = value;
        //            RaisePropertyChanged( "TypeRaschList" );
        //        }
        //    }
        //}
        public String TypeEnterLimite
        {
            get { return _typeEnterLimite; }
            set
            {
                if ( _typeEnterLimite != value )
                {
                    _typeEnterLimite = value;
                    RaisePropertyChanged( "TypeEnterLimite" );
                }
            }
        }

        /// <summary>
        /// ID отправленной транзакции
        /// </summary>
        public int ID
        {
            get { return _id; }
            set
            {
                if (_id != value)
                {
                    _id = value;
                    RaisePropertyChanged("ID");
                }
            }
        }


        #endregion

        #region event PropertyChangedEventHandler

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged ( string propertyName )
        {
            var handler = PropertyChanged;
            if ( handler != null )
            {
                handler( this, new PropertyChangedEventArgs( propertyName ) );
            }
        }

        #endregion

        public RmItem ()
        {

        }

        public RmItem ( SerializationInfo info, StreamingContext context)
        {
  
            ConsiderVMND = info.GetBoolean( "ConsiderVMND" );
            ComisBlock = info.GetDouble( "ComisBlock" );
            RunComicBlock = info.GetBoolean( "RunComicBlock" );
            ProfitBlock = info.GetDouble("ProfitBlock");

            Account = info.GetString("Account");
            AccountList = (List<String>)info.GetValue("AccountList", typeof(List<String>));

            ClientCode = info.GetString("ClientCode");
            ClientCodeList = (List<String>)info.GetValue("ClientCodeList", typeof(List<String>));

  
            Variable = info.GetString("Variable");
            //VariableList = (List<String>)info.GetValue("VariableList", typeof(List<String>));

            //Stage = info.GetInt32( "Stage" );
            //Unblock = info.GetInt32( "Unblock" );
            DrowDown = info.GetDouble("DrowDown");
            //ReductionGO = info.GetDouble("ReductionGO");
            //ReductionGOEvening = info.GetDouble("ReductionGOEvening");
            //TimeStrartreductionGOEvening = info.GetDouble("TimeStrartreductionGOEvening");

            TypeCalcutation = info.GetString("TypeRasch");
            //TypeRaschList = (List<String>)info.GetValue("TypeRaschList", typeof(List<String>));

            TypeEnterLimite = info.GetString("TypeEnterLimite");
            //TypeEnterLimiteList = (List<String>)info.GetValue("TypeEnterLimiteList", typeof(List<String>));

            ID = info.GetInt32("ID");

            UseDefensePofit = info.GetBoolean("UseDefensePofit");
            PlanProfit = info.GetDouble("PlanProfit");
            DecreaseProfit = info.GetDouble("DecreaseProfit");

        }

        public void GetObjectData ( SerializationInfo info, StreamingContext context )
        {
            info.AddValue( "ConsiderVMND", ConsiderVMND );
            info.AddValue( "ComisBlock", ComisBlock );
            info.AddValue( "RunComicBlock", RunComicBlock );
            info.AddValue("Account", Account);
            info.AddValue("AccountList", AccountList);
            info.AddValue("ClientCode", ClientCode);
            info.AddValue("ClientCodeList", ClientCodeList);
            info.AddValue("Variable", Variable);
            //info.AddValue( "Stage", Stage );
            //info.AddValue( "Unblock", Unblock );
            info.AddValue("DrowDown", DrowDown);
            //info.AddValue("ReductionGO", ReductionGO);
            //info.AddValue("ReductionGOEvening", ReductionGOEvening);
            //info.AddValue("TimeStrartreductionGOEvening", TimeStrartreductionGOEvening);
            info.AddValue("TypeCalcutation", TypeCalcutation);
            info.AddValue("TypeEnterLimite", TypeEnterLimite);
            info.AddValue("ProfitBlock", ProfitBlock);
            info.AddValue("ID", ID);

            info.AddValue("UseDefensePofit", UseDefensePofit);
            info.AddValue("PlanProfit", PlanProfit);
            info.AddValue("DecreaseProfit", DecreaseProfit);

        }
    }
}